<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>存储多个元素</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="memcached.setbykey.html">« Memcached::setByKey</a></li>
      <li style="float: right;"><a href="memcached.setmultibykey.html">Memcached::setMultiByKey »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.memcached.html">Memcached</a></li>
    <li>存储多个元素</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="memcached.setmulti" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::setMulti</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::setMulti</span> &mdash; <span class="dc-title">存储多个元素</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.setmulti-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::setMulti</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$items</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$expiration</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::setMulti()</strong></span>类似于<span class="methodname"><a href="memcached.set.html" class="methodname">Memcached::set()</a></span>， 但是使用了
   参数<code class="parameter">items</code>指定多个元素来替代单独的key/value设置以便于对多个元素的操作。<code class="parameter">expiration</code>
   参数指定的时候一次应用到所有的元素上。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.setmulti-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">items</code></dt>

     <dd>

      <p class="para">
       存放在服务器上的键／值对数组。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">expiration</code></dt>

     <dd>

      <p class="para">
       到期时间，默认为 0。 更多信息请参见<a href="memcached.expiration.html" class="link">到期时间</a>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.setmulti-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
   如需要则使用 <span class="methodname"><a href="memcached.getresultcode.html" class="methodname">Memcached::getResultCode()</a></span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.setmulti-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4408">
    <p><strong>示例 #1 <span class="function"><strong>Memcached::setMulti()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$items&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'key1'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'value1'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'key2'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'value2'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'key3'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'value3'<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setMulti</span><span style="color: #007700">(</span><span style="color: #0000BB">$items</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">300</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.setmulti-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="memcached.setmultibykey.html" class="methodname" rel="rdfs-seeAlso">Memcached::setMultiByKey()</a> - Store multiple items on a specific server</span></li>
    <li class="member"><span class="methodname"><a href="memcached.set.html" class="methodname" rel="rdfs-seeAlso">Memcached::set()</a> - 存储一个元素</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>